{extend name="common/layout" /}
{block name="main"}
<div class="admin-main layui-anim layui-anim-upbit">
    <div class="padding30">
        <h3 class="page-box-title">{:lang('Backup Files')}</h3>
    </div>
    <div class="" id="_listBox">
    <table class="layui-table" id="list" lay-filter="list"></table>
</div>
</div>
{/block}
{block name="footer"}
<script type="text/html" id="size">
    {{d.sortSize}}
</script>
<script type="text/html" id="action">
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="recover">{:lang('Recovery')}</a>
    <a href="{:url('downFile')}?type=sql&file={{d.name}}" class="layui-btn layui-btn-xs">{:lang('Download')}</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">{:lang('Delete')}</a>
</script>
<script>
    layui.use('table', function() {
        var table = layui.table, $ = layui.jquery;
        table.render({
            elem: '#list'
            ,url: '{:url("restore")}',
            method:'post'
            ,cols: [[
                {field:'name', title: "{:lang('File Name')}", width:"20%"}
                ,{field:'size', title: "{:lang('File Size')}", width:"20%",sort:true,templet:'#size'}
                ,{field:'time', title: "{:lang('Backup Time')}", width:"20%",sort:true}
                ,{field:'number', title: "{:lang('Volume Number')}", width:"20%"}
                ,{width:"18%", align:'center', toolbar: '#action'}
            ]]
        });
        table.on('tool(list)', function(obj) {
            var data = obj.data;
            if (obj.event === 'recover') {
                loading = layer.load(1, {shade: [0.1, '#fff']});
                layer.confirm("{:lang('Do you want to make sure that you want to import the data?')}",{icon: 0}, function (index) {
                    $.post("{:url('restoreData')}",{sqlfilepre:data.name},function(res){
                        layer.close(loading);
                        if(res.code==1){
                            layer.msg(res.msg, {time: 1000,icon:1});
                        }else{
                            layer.msg(res.msg, {time: 1000,icon:2});
                        }
                    });
                    layer.close(index);
                });
            }else if(obj.event === 'del'){
                layer.confirm("{:lang('Do you make sure that you want to delete the backup file?')}", {icon: 3}, function (index) {
                    loading = layer.load(1, {shade: [0.1, '#fff']});
                    $.post('{:url("delSqlFiles")}',{sqlfilename: data.name}, function (res) {
                        layer.close(loading);
                        if (res.code == 1) {
                            layer.msg(res.msg, {time: 1000,icon:1});
                            obj.del();
                        }else{
                            layer.msg(res.info,{time: 1000,icon:2});
                        }
                    });
                    layer.close(index);
                });
            }
        });
    });
</script>
{/block}